From f88384ec46a059e9601f09133c107a1cc77d3477 Mon Sep 17 00:00:00 2001 From: "atse@norwich.uk.xensource.com" Date: Fri, 22 Sep 2006 11:37:31 +0100 Subject: [PATCH] [XM] Error handling cleanup Introducing an OptionError exception to be used by all xm subcommands to signal an error in the arguments. "xm" will catch these and output the appropriate error and usage message. Detailed Changes: main.py: * Cleaned up imports and moved warning filter outside of import block. * Converted usage parameters and description to a python dict rather than strings to enable better usage help formatting. * Removed unused list_label domain command. * Added cmdHelp() prints out usage message for any command * Added shortHelp() prints out the default help message when xm is invoked with no arguments. * Added longHelp() prints out long help message when invoked with xm --help or xm help. * Added extra optional paramter to getDomains() so we can tell Xend not to poll devices. This will speed up xm list. (PENDING changes to Xend itself.) * Changed all references where 'dom' actually means 'domid' to use the correct name. * Changed 'xm list' header format to use printf formatting style. * Renamed xm_subcommand to xm_importcommand so it is more clear what it is doing (all xm commands are subcommands!) * Moved cpu_make_map() inside xm_vcpu_pin as an anonymous func. * Use OptionError whenever an invalid option is detected in xm. * Added proper catch and error printing for XendError and OptionErrors in main(). addlabel.py: cfgbootpolicy.py: dry-run.py: dump-policy.py: get-label.py: labels.py: loadpolicy.py: makepolicy.py: rmlabel.py: resources.py: * Replaced usage() with help() that is called from main.py * Replaced usage() invokation with raising OptionError opts.py: * Added very simple wrap() function that behaves differently to textwrap.wrap() * Added OptionError() * Replaced the string representation of Opt, Opts to output a nicely formatted usage message. * Changed class Opts itself will throw approriate OptionErrors. * Changed set_bool to recognise 'y' and 'n' as valid input create.py: * Some whitespace and column width cleanup. * throws OptionError if encounters option error. migrate.py: * Replace usage() message with the string representation of gopts. sysrq.py: * Replace usage message with throwing OptionErrors Signed-off-by: Alastair Tse --- tools/python/xen/xm/addlabel.py | 37 +- tools/python/xen/xm/cfgbootpolicy.py | 27 +- tools/python/xen/xm/console.py | 2 - tools/python/xen/xm/create.py | 71 ++- tools/python/xen/xm/dry-run.py | 20 +- tools/python/xen/xm/dumppolicy.py | 11 +- tools/python/xen/xm/getlabel.py | 38 +- tools/python/xen/xm/labels.py | 73 ++- tools/python/xen/xm/loadpolicy.py | 19 +- tools/python/xen/xm/main.py | 644 ++++++++++++++++----------- tools/python/xen/xm/makepolicy.py | 10 +- tools/python/xen/xm/migrate.py | 16 +- tools/python/xen/xm/opts.py | 90 +++- tools/python/xen/xm/resources.py | 25 +- tools/python/xen/xm/rmlabel.py | 32 +- tools/python/xen/xm/sysrq.py | 14 +- 16 files changed, 639 insertions(+), 490 deletions(-) diff --git a/tools/python/xen/xm/addlabel.py b/tools/python/xen/xm/addlabel.py index 0a11c35978..7bbe86eecc 100644 --- a/tools/python/xen/xm/addlabel.py +++ b/tools/python/xen/xm/addlabel.py @@ -19,19 +19,23 @@ """Labeling a domain configuration file or a resoruce. """ -import sys, os +import os +import sys + from xen.util import dictio from xen.util import security +from xen.xm.opts import OptionError -def usage(): - print "\nUsage: xm addlabel